local sk__dengxian = fk.CreateSkill {

  name = "sk__dengxian",

  tags = { Skill.Wake, },

}



sk__dengxian:addEffect(fk.EventPhaseStart, {
  name = "sk__dengxian",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__dengxian.name) and
      player:usedSkillTimes(sk__dengxian.name, Player.HistoryGame) == 0 and
      player.phase == Player.Start
  end,
  can_wake = function(self, event, target, player, data)
    return player:getMaxCards() == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"phase_draw", "phase_play"}, sk__dengxian.name, "#sk__dengxian-choose")
    room:setPlayerMark(player, sk__dengxian.name, choice)
  end,
})
sk__dengxian:addEffect(fk.EventPhaseChanging, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark(sk__dengxian.name) ~= 0 and data.phase == Player.Discard
  end,
  on_refresh = function(self, event, target, player, data)
    if player:getMark(sk__dengxian.name) == "phase_draw" then
      data.phase = Player.Draw
    else
      data.phase = Player.Play
    end
  end,
})

return sk__dengxian